package org.rambadger.command.providers;


import com.mongodb.gridfs.GridFS;
import com.sun.jersey.core.spi.component.ComponentContext;
import com.sun.jersey.spi.inject.Injectable;
import com.sun.jersey.spi.inject.PerRequestTypeInjectableProvider;
import org.rambadger.command.UploadConfiguration;
import org.rambadger.command.resource.util.UploadHelper;

import javax.ws.rs.core.Context;

/**
 * Jersey Provider for Injecting instances of {@link UploadHelper}
 */
public class UploadHelperProvider extends PerRequestTypeInjectableProvider<Context, UploadHelper> {
    @Context GridFS gridFS;
    @ConfigParam("upload") UploadConfiguration uploadConfig;

    /**
     * This should not have to be called manually, it is needed for Jersey to instantiate the provider
     */
    public UploadHelperProvider() {
        super(UploadHelper.class);
    }

    @Override
    public Injectable<UploadHelper> getInjectable(ComponentContext ic, Context context) {
        return new Injectable<UploadHelper>() {
            @Override
            public UploadHelper getValue() {
                return new UploadHelper(gridFS, uploadConfig);
            }
        };
    }
}
